﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Tcp;

using HR_Implements;

namespace ServerRemoting
{
    public partial class FServer : Form
    {
        public FServer()
        {
            InitializeComponent();
        }

        TcpChannel channel = null;

        private void btn_Start_Click(object sender, EventArgs e)
        {
            try{
                EmployeeRemotingObject r = new EmployeeRemotingObject();
                //1. Create channel
                channel = new TcpChannel(int.Parse(txt_Port.Text));
                //2. Register channel
                RemotingConfiguration.RegisterWellKnownServiceType(typeof(EmployeeRemotingObject),"HR_Implements",WellKnownObjectMode.SingleCall);
                //3. 
                ChannelServices.RegisterChannel(channel);
                toolStripStatusLabel1.Text = "Start";
            }catch(Exception ex){
                MessageBox.Show(ex.Message);
                toolStripStatusLabel1.Text = "Error";
            }
        }

        private void btn_Stop_Click(object sender, EventArgs e)
        {
            try{
                ChannelServices.UnregisterChannel(channel);
                toolStripStatusLabel1.Text = "Stoped";
            }
            catch (Exception ex){
                MessageBox.Show(ex.Message);
                toolStripStatusLabel1.Text = "Error";
            }
        }
    }
}
